﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TeachingEval.Sys.BLL;
using TeachingEval.Sys.IBLL;
using TeachingEval.Sys.Model;

namespace TeachingEval.Sys.UI.Controllers
{
    public class deparmentController : Controller
    {
        // GET: deparment

        public IdepartmentService DepartmentService = new departmentService();

        public ActionResult Index()
        {
            ViewData.Model = DepartmentService.GetEntities(a => true);
            return View();
        }
        public ActionResult Edit()
        {
            string url = Request.RawUrl;
            string temp = "";
            for (int i = 0; i < url.Length; i++)
            {
                char ch = url[i];
                if (ch >= '0' & ch <= '9')
                {
                    temp = temp + ch.ToString();
                }
            }
            ViewData.Model = DepartmentService.GetEntities(a => a.id==temp).FirstOrDefault();
            return View();
        }
        [HttpPost]
        public ActionResult Edit(department Department)
        {
            if (ModelState.IsValid)
            {
                DepartmentService.Update(Department);
            }
            return RedirectToAction("Index");
        }
        public ActionResult Delete()
        {
            string url = Request.RawUrl;
            string temp = "";
            for (int i = 0; i < url.Length; i++)
            {
                char ch = url[i];
                if (ch >= '0' & ch <= '9')
                {
                    temp = temp + ch.ToString();
                }
            }
            ViewData.Model = DepartmentService.GetEntities(a => a.id == temp).FirstOrDefault();
            return View();
        }
        [HttpPost]
        public ActionResult Delete(department Department)
        {
            if (ModelState.IsValid)
            {
                DepartmentService.Delete(Department);
            }
            return RedirectToAction("Index");
        }
        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(department Department)
        {
            if (ModelState.IsValid)
            {
                DepartmentService.Add(Department);
            }
            return RedirectToAction("Index");
        }
    }
}